//
//  GPNearbyShopTBCell.m
//  PFAMapDemo
//
//  Created by 原鹏飞 on 2018/11/5.
//  Copyright © 2018 原鹏飞. All rights reserved.
//

#import "GPNearbyShopTBCell.h"

@interface GPNearbyShopTBCell ()

@property (nonatomic, strong) UIImageView *shopImageView;
@property (nonatomic, strong) UILabel *shopNameLabel;
@property (nonatomic, strong) UILabel *distanceLabel;
@property (nonatomic, strong) UILabel *phoneNumLabel;
@property (nonatomic, strong) UIImageView *nextImageView;

@property (nonatomic, copy) NSString *address;
@property (nonatomic, assign) CLLocationDegrees latitude;
@property (nonatomic, assign) CLLocationDegrees longitude;

@end

@implementation GPNearbyShopTBCell

#pragma mark - 初始化

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self setupUI];
    }
    return self;
}


- (void)setupUI {
    self.selectionStyle = UITableViewCellSelectionStyleNone;
    
    _shopImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"img_default_shop"]];
    [self addSubview:self.shopImageView];
    [self.shopImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.equalTo(self).offset(5);
        make.height.width.mas_equalTo(50);
        //        make.bottom.equalTo(self).offset(-20);
    }];
    
    _shopNameLabel = [[UILabel alloc] init];
    _shopNameLabel.text = @"XXXX体验店";
    _shopNameLabel.font = [UIFont boldSystemFontOfSize:14];
    [self addSubview:self.shopNameLabel];
    [self.shopNameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.shopImageView).offset(5);
        make.left.equalTo(self.shopImageView.mas_right).offset(10);
        make.right.equalTo(self).mas_offset(-15);
        make.height.mas_lessThanOrEqualTo(30);
    }];
    
    _distanceLabel = [[UILabel alloc] init];
    self.distanceLabel.text = @"距离5.5公里";
    self.distanceLabel.font = [UIFont systemFontOfSize:10];
    [self addSubview:self.distanceLabel];
    [self.distanceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.shopNameLabel.mas_bottom).offset(5);
        make.left.equalTo(self.shopNameLabel);
        make.height.mas_equalTo(15);
    }];
    
    _phoneNumLabel = [[UILabel alloc] init];
    self.phoneNumLabel.text = @"联系方式：0851-77778888";
    self.phoneNumLabel.font = [UIFont systemFontOfSize:12];
    [self addSubview:self.phoneNumLabel];
    [self.phoneNumLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.shopImageView.mas_bottom).offset(5);
        make.left.equalTo(self.shopImageView);
        make.height.mas_equalTo(15);
    }];
    
    _nextImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"icon_order_unselected"]];
    [self addSubview:self.nextImageView];
    [self.nextImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self).offset(-5);
        make.bottom.equalTo(self.shopImageView);
        make.height.width.width.mas_equalTo(15);
    }];
}


/**
 在这里可以布局cell中的元素,当cell的frame改变或旋转时会触发这个方法
 */
- (void)layoutSubviews {
    [super layoutSubviews];
}

/**
 当需要在上下文中绘制时可以在这里处理

 @param rect rect
 */
- (void)drawRect:(CGRect)rect {
    [super drawRect:rect];
}


#pragma mark - 模型赋值

- (void)setModel:(GPNearbyShopTBCellModel *)model {
    _model = model;
    
//    [_shopImageView setImage:model.shopImg];
    _shopNameLabel.text = model.shopName;
//    _distanceLabel.text = model.distance;
//    _phoneNumLabel.text = model.phoneNum;
    
    _address = model.address;
    _latitude = model.latitude;
    _longitude = model.longitude;
}


- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
